package cc.xsubj.engine.entity;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

import cc.xsubj.engine.ResourceManager;

public class MapEntity extends Entity {
	
	private TiledMap map;

	public MapEntity(String ref) {
		this(ResourceManager.getMap(ref));
	}
	
	public MapEntity(TiledMap map) {
		super(0, 0);
		this.map = map;
		this.width = map.getWidth() * map.getTileWidth();
		this.height = map.getHeight() * map.getTileHeight();
	}
	
	public void render(GameContainer container, Graphics g)
			throws SlickException {
		
		int sx = (int)(world.camera.cameraX / map.getTileWidth());
		int sy = (int)(world.camera.cameraY / map.getTileHeight());
		
		int x = sx * map.getTileWidth();
		int y = sy * map.getTileHeight();
		
		// Plus to each of these so we don't see black around the edges.
		int viewWidthTilesX = (int)(world.camera.getViewport().getWidth() / map.getTileWidth()) + 1;
		int viewWidthTilesY = (int)(world.camera.getViewport().getHeight() / map.getTileHeight()) + 2;
		
		map.render(x, y, sx, sy, viewWidthTilesX, viewWidthTilesY, false);
	}

}
